package com.suxin.kettle;

import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.util.EnvUtil;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;

/**
 * @author Tang
 * @classname KettleMain
 * @description [ TODO ]
 * @date 2021/1/12 13:35
 */
public class KettleMain {

    public static void main(String[] args) throws Exception{
        runTransfer(new String[]{}, "G:\\javaConfig\\pdi-ce-7.1.0.0-12\\data-integration\\tr1.ktr");
    }

    public static void runTransfer(String[] params, String ktrPath) throws Exception{
        Trans trans = null;
        KettleEnvironment.init(); // 初始化
        EnvUtil.environmentInit();
        TransMeta transMeta = new TransMeta(ktrPath);
        // 转换
        trans = new Trans(transMeta);
        // 执行转换
        trans.execute(params);
        // 等待转换执行结束
        trans.waitUntilFinished();
        if (trans.getErrors() > 0) {
            throw new Exception("There are errors during transformation exception!");
        }
    }

}